home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Demo / cgi / realcgitest.py < prev   
Encoding:
Python Source  |  1996-09-09  |  1.1 KB  |  46 lines  |  [TEXT/Pyth]

  1. """cgitest - A minimal CGI applet. Echos parameters back to the client.
  2. """
  3.  
  4. from MiniAEFrame import AEServer, MiniApplication
  5.  
  6. class CGITest(AEServer, MiniApplication):
  7.     
  8.     def __init__(self):
  9.         MiniApplication.__init__(self)
  10.         AEServer.__init__(self)
  11.         self.installaehandler('aevt', 'oapp', self.open_app)
  12.         self.installaehandler('aevt', 'quit', self.quit)
  13.         self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
  14.         self.mainloop()
  15.  
  16.     def quit(self, **args):
  17.         self.quitting = 1
  18.         
  19.     def open_app(self, **args):
  20.         pass
  21.                 
  22.     def cgihandler(self, pathargs, **args):
  23.         rv = """HTTP/1.0 200 OK
  24. Server: NetPresenz; python-cgi-script
  25. MIME-Version: 1.0
  26. Content-type: text/html
  27.  
  28. <title>Python CGI-script results</title>
  29. <h1>Python CGI-script results</h1>
  30. <hr>
  31. """
  32.         rv = rv+'<br><b>Direct object:</b> %s\n'%pathargs
  33.         
  34.         for key in args.keys():
  35.             if key[0] != '_':
  36.                 rv = rv + '<br><b>%s:</b> %s\n'%(key, args[key])
  37.         rv = rv +'<hr>\nSee you next time!\n'
  38.         
  39.         # Note: if you want to quit after each request enable the line
  40.         # self.quitting = 1
  41.         
  42.         return rv
  43.  
  44. if __name__ == '__main__':
  45.     CGITest()
  46.